package cn.xqj.order.service.impl;

import cn.xqj.basic.query.BaseQuery;
import cn.xqj.basic.util.PageList;
import cn.xqj.basic.util.getLogininfo;
import cn.xqj.order.domain.OrderPetAcquisition;
import cn.xqj.order.query.OrderPetAcquisitionQuery;
import cn.xqj.order.service.IOrderPetAcquisitionService;
import cn.xqj.basic.service.impl.BaseServiceImpl;
import cn.xqj.org.domain.Employee;
import cn.xqj.org.domain.Shop;
import cn.xqj.org.mapper.EmployeeMapper;
import cn.xqj.org.mapper.ShopMapper;
import cn.xqj.user.domain.Logininfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * 业务实现类：
 */
@Service
public class OrderPetAcquisitionServiceImpl extends BaseServiceImpl<OrderPetAcquisition> implements IOrderPetAcquisitionService {


    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private ShopMapper shopMapper;

    @Override
    public PageList<OrderPetAcquisition> pageQuery(OrderPetAcquisitionQuery query, HttpServletRequest request) {
        Logininfo logininfo = getLogininfo.getLogininfo(request);
        Employee employee = employeeMapper.findByLogininfoId(logininfo.getId());
        if (employee.getShop_id() != null) {
            Shop shop = shopMapper.findOne(employee.getShop_id());
            if (shop.getAdmin_id() != null) {
                query.setEmpId(employee.getId());
            }
            query.setShopId(shop.getId());
        }


        return super.pageQuery(query);
    }
}
